<?php
class File_model extends MY_Model
{
	public $table = 'files';
	
	public function __construct()
	{
		parent::__construct();
	}
	
	public function get_by_name($name, $search = NULL)
	{
		$search_query = (is_null($search)) ? NULL : " AND FILE_ITEMS.FILENAME LIKE ('%$search%') ";
		$sql = "SELECT FILE_ITEMS.*
		FROM FILES
		JOIN FILE_ITEMS ON FILE_ITEMS.FILE_ID = FILES.ID
		WHERE FILES.NAME = '$name'
		$search_query
		ORDER BY FILE_ITEMS.ID ASC
		";
		$rs['result'] = $this->get($sql);
		$rs['pagination'] = $this->pagination;
		return $rs;
	}
	
}
